#include "DynamicModule.hpp"

//--------------------------------------------------
// Constructor / Destructor
//--------------------------------------------------
DynamicModule::DynamicModule()
	: _hModule(NULL)
{
}

DynamicModule::~DynamicModule()
{
	Unload();
}

//--------------------------------------------------
// Load / Unload
//--------------------------------------------------
bool DynamicModule::Load(const std::string &path)
{
	SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);		//Do not display error message boxes
	//_hModule = ::LoadLibrary(LPCWSTR(path.c_str()));
	_hModule = ::LoadLibraryA(path.c_str());
	return (_hModule != NULL);
}

bool DynamicModule::Unload()
{
	bool result = true;
	if (_hModule != NULL)
		result = FreeLibrary(_hModule) ? true : false;
	_hModule = NULL;
	return result;
}

//--------------------------------------------------
// Find Symbol
//--------------------------------------------------
void *DynamicModule::FindSymbol(const std::string &name) const
{
	return ::GetProcAddress(_hModule, name.c_str());
}
